package com.ceadeal.admin.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.util.Map;

/**
 * 功能描述: Index Controller
 *
 * 作者: Yzw
 * 日期: 2017-03-04 10:56:42
 */
@Controller
public class IndexController implements ServletContextAware {

    private ServletContext servletContext;

    @Value("${system.name}")
    private String systemName;

    @Value("${system.version}")
    private String version;

    @Value("${system.description}")
    private String description;

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    @GetMapping("/")
    public String index() {
        return "index";
    }

    @GetMapping("/main")
    public String welcome(Map<String, Object> model) {
        model.put("systemName", this.systemName);
        model.put("systemVersion", this.version);
        model.put("systemDescription", this.description);
        model.put("javaVersion", System.getProperty("java.version"));
        model.put("javaHome", System.getProperty("java.home"));
        model.put("osName", System.getProperty("os.name"));
        model.put("osArch", System.getProperty("os.arch"));
        model.put("serverInfo", this.servletContext.getServerInfo());
        model.put("servletVersion", this.servletContext.getMajorVersion() + "." + this.servletContext.getMinorVersion());
        return "/common/main";
    }

    @RequestMapping("/login")
    public String login() {
        return "/login";
    }

    @RequestMapping("/auth")
    public String auth(Map<String, Object> model) {
        return "redirect:/index";
    }

}
